package com.xy.mainp.huaban.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xy.debug.SystemConfig;
import com.xy.img.GlideUtil;
import com.xy.mainp.R;
import com.xy.mainp.model.huaban.ImgEntity;
import com.xy.view.CircleImageView;

/**
 * Created by John on 2016/11/23.
 */

public class ImgVpTittle extends LinearLayout {

    private CircleImageView headview;
    private TextView text;

    public ImgVpTittle(Context context) {
        this(context,null);
    }

    public ImgVpTittle(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ImgVpTittle(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        setOrientation(HORIZONTAL);
        setGravity(Gravity.CENTER);
        headview = new CircleImageView(context);
        headview.setScaleType(ImageView.ScaleType.CENTER_CROP);
        int px = SystemConfig.dp2px(context, 17);
        headview.setLayoutParams(new ViewGroup.LayoutParams(px,px));
        addView(headview);
        text = new TextView(context);
        text.setTextSize(14);
        text.setTextColor(getResources().getColor(R.color.white));
        MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.leftMargin = SystemConfig.dp2px(context, 10);
        text.setLayoutParams(layoutParams);
        addView(text);
    }

    public void setData(ImgEntity data){
        GlideUtil.loadImageR(data.getAuthorImg(),headview,R.drawable.usr_headerbox_cev_img);
        text.setText(data.getTitle());
    }
}
